﻿namespace AnyOffice.WebControls
{
    using System;
    using System.Data;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    public class HyperLinkColumn : ITemplate
    {
        private string paramField;
        private string text;
        private string url;

        public HyperLinkColumn(string displayText, string navUrl, string bindField)
        {
            this.text = displayText;
            this.url = navUrl;
            this.paramField = bindField;
        }

        public void InstantiateIn(Control container)
        {
            HyperLink child = new HyperLink();
            child.DataBinding += new EventHandler(this.OnDataBinding);
            container.Controls.Add(child);
        }

        public void OnDataBinding(object sender, EventArgs e)
        {
            HyperLink link = (HyperLink) sender;
            GridViewRow namingContainer = (GridViewRow) link.NamingContainer;
            link.Text = ((DataRowView) namingContainer.DataItem).Row[this.text].ToString();
            string[] strArray = this.paramField.Split(new char[] { ',' });
            string[] strArray2 = new string[strArray.Length];
            for (int i = 0; i < strArray2.Length; i++)
            {
                strArray2[i] = ((DataRowView) namingContainer.DataItem)[strArray[i]].ToString();
            }
            link.NavigateUrl = string.Format(this.url, (object[]) strArray2);
            link.Target = "_blank";
        }
    }
}

